package coder.taiji.test.springnetty.tcp.outbound;

import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;

/**
 * describe:
 *
 * @author helloworldyu
 * @date 2018/3/14
 */
public class FirstOutboundChannel extends ChannelOutboundHandlerAdapter {
	@Override
	public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
		System.out.println("===============firstoutbound===============");
		//===============获取 byte 发送=================
		//等待发送成功的通知。
		ChannelFuture channelFuture = ctx.writeAndFlush(msg);
		channelFuture.addListener(future -> {
			if (future.isSuccess()) {
				promise.setSuccess();
			} else {
				promise.setFailure(future.cause());
			}
		});
	}
}